<html lang="zh_CN">
{% include "common/table_page_head.html" %}
<body style="overflow: hidden;">
<div class="layui-fluid">
    <script type="text/html" id="list_toolbar">
        <div class="layui-btn-container" style="padding-top: 1px;">
            <div style='float:left; height: 30px;'>
                <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="addData"
                        id="addOrgItem"><span
                        class='glyphicon glyphicon-plus'></span>&nbsp;新增
                </button>
                <button class="layui-btn layui-btn-sm" lay-event="refreshData"><span
                        class='glyphicon glyphicon-repeat'></span>&nbsp;刷新
                </button>
            </div>
            <div class='input-group input-group-sm' style='float:left; width:280px; height: 30px;'>
                <input type="text" id="query_text" value="{{ search_text }}" placeholder="快速查询..." class='form-control'>
                <span class='input-group-btn'>
                    <button class='btn btn-default' lay-event="quickQuery"><span
                            class='glyphicon glyphicon-search'></span>查询</button>
                </span>
            </div>
        </div>
    </script>
    <script type="text/html" id="actionBar">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
    <table lay-filter="datalist" class="layui-table" id="datalist">
        <thead>
        <tr>
            <th lay-data="{field: 'fid', hide: true}"></th>
            <th lay-data="{field:'ftitle'}">标题</th>
            <th lay-data="{field:'fcontext'}">内容</th>
            <th lay-data="{field:'fpushdatetime', hide: true}">发布时间</th>
            <th lay-data="{field:'fcreatedeptname', width:200}">登记部门</th>
            <th lay-data="{field:'fcreatorname', width:100}">登记人</th>
            <th lay-data="{field:'fcreatetime', width:160}">登记时间</th>
            <th lay-data="{toolbar:'#actionBar', width:120}">操作</th>
        </tr>
        </thead>
        <tbody>
        {% for d in page_data.items %}
            <tr>
                <td>{{ d.fid }}</td>
                <td>{{ d.ftitle }}</td>
                <td>{{ d.fcontext }}</td>
                <td>{{ d.fpushdatetime }}</td>
                <td>{{ d.fcreatedeptname }}</td>
                <td>{{ d.fcreatorname }}</td>
                <td>{{ d.fcreatetime }}</td>
                <td></td>
            </tr>
        {% endfor %}
        </tbody>
    </table>
    <div id="data_list_page"></div>
</div>
</body>
<script type="text/javascript">
    let currentRow = {};

    layui.use(['table', 'laypage'], function () {
        var table = layui.table;
        var laypage = layui.laypage;
        //初始化数据表格
        table.init('datalist',
            {
                toolbar: '#list_toolbar',
                defaultToolbar: ['exports'],
                height: 'full-80',
                page: false,
                limit: 20
            }
        );
        //头工具栏事件
        table.on('toolbar(datalist)', function (obj) {
            switch (obj.event) {
                case 'addData':
                    addDayReport();
                    break;
                case 'refreshData':
                    window.location.reload();
                    break;
                case 'quickQuery':
                    doSearch();
                    break;
            }
        });
        $("#query_text").keyup(function (event) {
            if (event.keyCode === 13) {
                doSearch();
            }
        });
        //触发行单击事件
        table.on('row(datalist)', function (obj) {
            //console.log(obj.tr) //得到当前行元素对象
            //console.log(obj.data) //得到当前行数据
            obj.tr.parent().find('tr').removeClass('active')
            obj.tr.addClass('active') //选中行加特殊背景颜色
            currentRow = obj.data;
        });
        //监听行工具事件
        table.on('tool(datalist)', function (obj) {
            //console.log(obj)
            let data = obj.data;
            if (obj.event === 'edit') {
                editDayReport(data);
            }
            if (obj.event === 'del') {
                delData(data);
            }
        });
        //执行一个laypage实例
        laypage.render({
            elem: 'data_list_page', //注意，这里的ID，不用加 # 号
            count: {{ count }}, //数据总数，从服务端得到
            limit: {{ limit }}, //每页行数
            limits: [10, 20, 30, 40, 50],
            curr: {{ page }}, //当前页码
            jump: function (obj, first) {
                //obj包含了当前分页的所有参数，比如：
                //console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
                //console.log(obj.limit); //得到每页显示的条数
                //首次不执行
                if (!first) {
                    window.location.href = "/oa/PersonUse/DayReport/reportList?page=" + obj.curr + "&limit=" + obj.limit + "&search_text=" + J_u_encode($("#query_text").val());
                }
            }
        });
    });

    function doSearch() {
        window.location.href = "/oa/PersonUse/DayReport/reportList?search_text=" + J_u_encode($("#query_text").val());
    }

    function addDayReport() {
        tlv8.portal.dailog.openDailog("添加日报", "/oa/PersonUse/DayReport/dialog/editData", 800, 500, function (r) {
            doSearch();
        }, false);
    }

    function editDayReport(data) {
        tlv8.portal.dailog.openDailog("编辑日报", "/oa/PersonUse/DayReport/dialog/editData?rowid=" + data.fid, 800, 500, function (r) {
            doSearch();
        }, false);
    }

    function delData(data) {
        layui.layer.confirm("数据删除后不能恢复，确认删除吗？", function () {
            $.ajax({
                url: "/oa/PersonUse/DayReport/deleteData",
                type: "post",
                async: true,
                data: {rowid: data.fid},
                dataType: "json",
                success: function (re) {
                    if (re.state === true) {
                        layui.layer.msg("删除成功！");
                        doSearch();
                    } else {
                        layui.layer.alert("删除失败：" + re.msg);
                    }
                }
            });
        });
    }
</script>
</html>